/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once

#include "highfive/H5File.hpp"

#include "DBManager/IRepository/Input/Table/ITableSummaryRepository.h"
#include "DBManager/Repository/HDF5/Base/SingleRepositoryBase.h"

template <>
inline HighFive::DataType HighFive::create_datatype<SG::DBManager::SummaryInfo<SG::DataStructure::FEM::TableTypes>> ()
{
    HighFive::CompoundType compoundType = { { "EID", HighFive::create_datatype<SG::DataStructure::Common::Id> () },
                                            { "TYPE", HighFive::create_datatype<SG::DataStructure::Common::UI8> () },
                                            { "INDEX", HighFive::create_datatype<SG::DataStructure::Common::I64> () } };
    return compoundType;
}

SG_DBMANAGER_HDF5_NAMESPACE_OPEN
class TableSummaryRepository : public ITableSummaryRepository,
                               public SingleRepositoryBase<SG::DBManager::SummaryInfo<SG::DataStructure::FEM::TableTypes>>
{
  public:
    explicit TableSummaryRepository (HDF5Database& database);

    enum DATASET : std::uint8_t
    {
        MainDataset,   ///< 主表
        IndexDataset,  ///< ID表单
    };

    /**
     * @brief   : 初始化该表数据
     * @return  :
     * @author  : wxc
     * @date    : 2024.11.03
     */
    void InitDataset () override;

    /**
     * @brief   :
     * @author  : wxc
     * @date    : 2024.11.04
     */
    void InitialDatasetInfo () override;

    /**
     * @brief   : 获取指定单元的类型
     * @param   : Eid
     * @return  :
     * @author  : wxc
     * @date    : 2024.11.03
     */
    SG::DataStructure::FEM::TableTypes GetTableType (SG::DataStructure::Common::Id Eid) override;

    /**
     * @brief   : 类型为`type`的单元的数量
     * @param   : type
     * @return  :
     * @author  : wxc
     * @date    : 2024.11.03
     */
    std::size_t GetTableSize (SG::DataStructure::FEM::TableTypes type) override;
};
SG_DBMANAGER_HDF5_NAMESPACE_CLOSE